//
//  UIFont+DD.m
//  GSDache
//
//  Created by dudu on 16/12/5.
//  Copyright © 2016年 tanyin. All rights reserved.
//

#import "UIFont+DD.h"

@implementation UIFont (DD)

- (CGFloat)oneLineWithString:(NSString *)str {
    if (!str) {
        return 0;
    }
    if ([str isEqualToString:@""]) {
        return 0;
    }
    CGSize size = [str boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:self} context:nil].size;
    return size.width+0.5;
}
- (CGFloat)oneLineWithAttriString:(NSAttributedString *)str {
    if (!str) {
        return 0;
    }
    if ([str.string isEqualToString:@""]) {
        return 0;
    }
    CGSize size = [str.string boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:self} context:nil].size;
    return size.width+0.5;
}

- (CGFloat)heightWithString:(NSString *)str Width:(CGFloat)width {
    if (!str) {
        return 0;
    }
    if ([str isEqualToString:@""]) {
        return 0;
    }
    CGSize size = [str boundingRectWithSize:CGSizeMake(width, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:self} context:nil].size;
    return size.height+0.5;
}

- (CGSize)sizeWithString:(NSString *)str Width:(CGFloat)width {
    if (!str) {
        return CGSizeZero;
    }
    if ([str isEqualToString:@""]) {
        return CGSizeZero;
    }
    CGSize size = [str boundingRectWithSize:CGSizeMake(width, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:self} context:nil].size;
    return CGSizeMake(size.width+0.5, size.height+0.5);
}

@end
